import cn.edu.dgut.infomation.LocalUserInfo;
import cn.edu.dgut.utils.ReadFile;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/bindInfo")
public class BindInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String,String> infoMap = (Map<String, String>) request.getSession().getAttribute("isLogin");
        String user_number = infoMap.get("user_number");
        //根据工号查找用户
        LocalUserInfo user = new ReadFile().find(user_number);
        String phone_number = request.getParameter("phone_number");
        String qq = request.getParameter("qq");
        String weixin = request.getParameter("weixin");
        String github = request.getParameter("Github");
        if(phone_number.trim().equals("")){
            phone_number=null;
        }
        if(qq.trim().equals("")){
            qq=null;
        }
        if(weixin.trim().equals("")){
            weixin=null;
        }
        if(github.trim().equals("")){
            github=null;
        }
        user.setPhone_number(phone_number);
        user.setQq(qq);
        user.setWeixin(weixin);
        user.setGithub(github);
        new ReadFile().resetUserInfo(user);
        response.sendRedirect("/info.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
